﻿/*
 *	Copyright (c) 2009 Queensland University of Technology. All rights reserved.
 *	The QUT Bioinformatics Collection is open source software released under the 
 *	Microsoft Public License (Ms-PL): http://www.microsoft.com/opensource/licenses.mspx.
 */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

#if ! SILVERLIGHT
using System.Windows.Navigation;
#endif


namespace QUT.Bio.SilverMap {
	/// <summary>
	/// This is a simple "find" box that is used to filter results in the mapa view.
	/// </summary>
	public partial class SearchControl : UserControl {
		public SearchControl () {
			InitializeComponent();
		}

		/// <summary> Get or set the contents of the text box.
		/// <para>Leading and trailing blank space is removed in both the accessor and mutator.</para>
		/// </summary>
		public string SearchText {
			get {
				return searchText.Text.Trim();
			}
			set {
				searchText.Text = value == null ? "" : value.Trim();
			}
		}

		/// <summary> FindEvent fires when the user clicks the 'Find' button or presses enter while the search text
		/// holds focus.
		/// </summary>
		public event Action<SearchControl> FindEvent;

		/// <summary> ClearEvent fires when the user clicks the 'Clear' button.
		/// </summary>
		public event Action<SearchControl> ClearEvent;

		/// <summary> Event handler for KeyDown event of the search box.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void SearchTextKeyDown ( object sender, KeyEventArgs e ) {
			if ( e.Key == Key.Enter && FindEvent != null ) {
				FindEvent( this );
			}
		}

		/// <summary> Event handler for the 'Find' button.
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void FindClick ( object sender, RoutedEventArgs e ) {
			if ( FindEvent != null ) {
				FindEvent( this );
			}
		}

		/// <summary> Event handler for the 'Clear' button. 
		/// </summary>
		/// <param name="sender"></param>
		/// <param name="e"></param>
		private void ClearClick ( object sender, RoutedEventArgs e ) {
			if ( ClearEvent != null ) {
				ClearEvent( this );
			}
		}
	}
}
